package com.zgs.mall.product.web;

import com.zgs.mall.product.entity.CategoryEntity;
import com.zgs.mall.product.service.CategoryService;
import com.zgs.mall.product.vo.Catalog2Vo;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;
import java.util.Map;

@Controller
public class IndexController {
    @Autowired
    private CategoryService categoryService;
    @GetMapping({"/","/index.html"})
    public  String indexPage(Model model){
        //1.查出所有的一级分类
        List<CategoryEntity> categorys=categoryService.getLevel1Category();
        model.addAttribute("categorys",categorys);
        return "index";
    }
    //获取所有分类返回json
    @GetMapping("index/json/catalog.json")
    @ResponseBody
    public Map<String,List<Catalog2Vo>> getCatelogJson(){
        Map<String,List<Catalog2Vo>> catelogMap= categoryService.getCatelogJson();
        return catelogMap;
    }
}
